<template>
	
	<view style="background: url('https://cdnjson.com/images/2023/09/28/80d3041dc302dfa770e11477b4491e9b.jpg'); position: fixed;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
		z-index: -1;">
		<!-- 自定义顶部导航栏 -->
		<topNavbar></topNavbar>   
		
		<button class="enter-bt" @click="deviceEnter">
			<image src="https://cdnjson.com/images/2023/09/26/_20230926090534.png" style="width: 50px; height: 50px;"></image>
			<text style="color: #ffffff;">扫描二维码</text>
			</button>
			
	</view>
	
</template>
 
<script>
	export default{
		data(){
			return{
			}
		},
		methods: {
			deviceEnter(){
				console.log("点击设备录入 ")
				uni.scanCode({
					// onlyFromCamera: true, //只允许相机 
					success: (res) => {
						console.log(res.result,"扫描结果=====")
						 // 往服务器对比
						var scanStr = res.result
						console.log(scanStr.substring(0,4),"字符串前四 ------")
						
						if (scanStr.substring(0,4) == 'SMAC') {
							let data = { scan: res.result}
							uni.navigateTo({
								url: '/pages/adminVue/deviceEnterUpload?data=' + encodeURIComponent(JSON.stringify(data))
							})
						} else{
							uni.showToast({
								title: '您扫描的二维码不正确，请重新扫码',
								duration: 2000,
								icon: 'none'
							})
						}
						
						
						
						
					}
				})
				
			}
		}
	}
</script>
 
<style lang="scss">

	
	.enter-bt{
		width: 200px;
		height: 20%;
		display: flex;
		margin-top: 50%;
		justify-content: center;
		border-radius: 15px;
		align-items: center;
		background-color: #00aaff;
		// background: linear-gradient(to right, blue, pink);
	}
</style>